package com.apes.fn.server.servicePlan.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @program: apes-server
 * @description:
 * @author: czs
 * @create: 2022-11-19 16:47
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PriceApprovalReport.CONST_TABLE_NAME, indexes ={
        @Index(name = "IDX_PRICE_APPROVAL_ITEM_ID", columnList = "plan_item_id", unique = false)
})
public class PriceApprovalReport extends BaseModel {
    public static final String CONST_TABLE_NAME = "price_approval_report";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "价格审核报表", padding = 12)
    private String id;

    @Column(name = "plan_id",nullable = false, length = 48)
    @Comment("方案编码")
    private String planId;

    @Column(name = "plan_item_id",nullable = false, length = 48)
    @Comment("方案明细编码")
    private String planItemId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id",nullable = false, referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "request_person", referencedColumnName = "id")
    @Comment("申请人")
    private PartyRole requestPerson;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "process_person", referencedColumnName = "id")
    @Comment("处理人")
    private PartyRole processPerson;


    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "request_date")
    @Comment("申请日期")
    private Date requestDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "process_date")
    @Comment("处理日期")
    private Date processDate;


    @Column(name = "Approval_result", length = 256)
    @Comment("本次审核结果")
    private String approvalResult;//1:同意,0:拒绝

    @Column(name = "Approval_remark", length = 256)
    @Comment("本次审核备注")
    private String approvalRemark;

    @Column(name = "last_approval_id", length = 128)
    @Comment("上次审核编码")
    private String lastApprovalId;

    @Column(name = "last_approval_result", length = 256)
    @Comment("上次审核结果")
    private String lastApprovalResult;

    @Column(name = "last_approval_remark", length = 256)
    @Comment("上次审核备注")
    private String lastApprovalRemark;

    @Column(name = "last_pft_price_unit",  columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("上次审核通过优惠单价")
    private double lastPftPriceUnit = 0;

    @Column(name = "limit_level", length = 16)
    @Comment("限价级别")
    private String limitLevel;

    @Column(name = "price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("销售单价")
    private double priceUnit = 0;

    @Column(name = "pft_price_unit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("优惠单价")
    private double pftPriceUnit = 0;

    @Column(name = "sales_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("销售金额")
    private double salesAmount = 0;

    @Column(name = "discount_rate", nullable = false, columnDefinition = ApesConst.FIELD_ROUND_16_8)
    @Comment("折扣率")
    private double discountRate = 0;


    @Column(name = "shop_owner_price_limit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("店长限价")
    private double shopOwnerPriceLimit = 0;

    @Column(name = "cso_price_limit", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("销售总监限价")
    private double csoPriceLimit = 0;

    @Column(name = "base_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("销售基准价")
    private double basePrice = 0;

    @Column(name = "refer_tax", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("参考成本")
    private double referTax = 0;

    @Column(name = "supply_Chain_Management", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("供应链管理费用")
    private double supplyChainManagement = 0;

    //30天内
    @Column(name = "max_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("最高售价")
    private double maxAmount = 0;

    //30天内
    @Column(name = "min_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("最低售价")
    private double minAmount = 0;

    @Column(name = "approval_num", columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("审核次数")
    private double approvalNum = 0;

}
